package org.beef.core.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Component
public class SessionUtil<T> implements CommandLineRunner{
	
	Class<T> t;
	
	private static String cacheName; 
	
	public static <T> T getI() {
		RequestAttributes ra = RequestContextHolder.getRequestAttributes();  
		HttpServletRequest request = ((ServletRequestAttributes)ra).getRequest();  
		HttpSession session = request.getSession();
		Object attribute = session.getAttribute(cacheName);
		if (attribute!=null) {
			return (T)attribute;
		}
		return null;
	}
	
	public void setT(T t) {
		
	}

	public void run(String... args) throws Exception {
		System.out.println("sdfsdf");
	}
}
